<%@page import="com.neusoft.weixin.utils.MessageUtil"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<% String appPath = request.getContextPath();%>    
<!DOCTYPE html>
<html>
  <head>
    <title>公众号设置</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <script type="text/javascript">
	    var appPath = '${ctx}';
    </script>
  </head>
  <body>
  <br>
  <div class="col-xs-7">
  <div class="alert alert-warning fade in">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    <div id="alert"><strong>注意!</strong> 请先完善公众号设置。</div>
  </div>
<form class="form-horizontal" role="form" id="config">
  <div class="form-group">
    <label for="WEIXINNUM" class="col-sm-2 control-label">微信号</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="WEIXINNUM" name="WEIXINNUM" placeholder="微信号" required>
    </div>
  </div>
  <!--<div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">原始ID</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="inputPassword3" placeholder="原始ID" required>
    </div>
  </div>
   <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">类型</label>
    <div class="col-sm-10">
	    <div class="radio-inline">
		  <label>
		    <input type="radio" name="weixintype" id="subscribe" value="subscribe" checked>
		    订阅号
		  </label>
		</div>
		<div class="radio-inline">
		  <label>
		    <input type="radio" name="weixintype" id="service" value="service">
		  服务号
		  </label>
		</div>
    </div>
  </div> -->
  <div class="form-group">
    <label for="URL" class="col-sm-2 control-label">服务器URL</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="URL" name="URL" placeholder="服务器URL">
    </div>
  </div>
  <div class="form-group">
    <label for="TOKEN" class="col-sm-2 control-label">Token</label>
    <div class="col-sm-10">
      <input type="text" class="form-control" id="TOKEN" name="TOKEN" placeholder="Token">
      <span class="help-block">以下配置为创建自定义菜单使用</span>
    </div>
  </div>
  
  <div class="form-group">
    <label for="APPID" class="col-sm-2 control-label">appId</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="APPID" name="APPID" placeholder="用户唯一凭证">
    </div>
    <label for="APPSECRET" class="col-sm-2 control-label">appSecret</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="APPSECRET" name="APPSECRET" placeholder="用户唯一凭证密钥  ">
    </div>
  </div>
  <div class="form-group">
    <label for="PROXYHOST" class="col-sm-2 control-label">代理地址</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="PROXYHOST" name="PROXYHOST" placeholder="代理地址  ">
    </div>
    <label for="proxyPort" class="col-sm-2 control-label">代理端口</label>
    <div class="col-sm-4">
      <input type="text" class="form-control" id="PROXYPORT" name="PROXYPORT" placeholder="代理端口">
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10 text-right">
      <button type="button" id="save" class="btn btn-primary">保存</button>
    </div>
  </div>
</form>
</div>
<script type="text/javascript" src="${ctx}/static/common/common.js"></script>
<script type="text/javascript" src="${ctx}/static/common/jquery.extend.js"></script>
<script type="text/javascript">

$(document).ready(function(){
	
	$("#save").click(saveConfig);
	initConfig();
	
});

function saveConfig(){
	
	var configData = getFormData('config');
	
	$.ajax({
		   type: "POST",
		   async: false,//同步发送请求数据
		   url: appPath+"/menu?method=saveConfig",
		   data : {
			   'data' : $.toJSONString(configData)
		   },
		   dataType:"json",
		   beforeSend : function(){
//			   $.showProgress();
		   },
		   complete : function(){
//			   $.hideProgress();
		   },
		   timeout:120*1000,
		   dataType:"json",
	       success: function(data){
	    	   if(data){
	    		   $("#alert").html(data.detail);
	    	   }
		   },
		   error:function(xhr,textStatus,errorThrown){
		   }
		}); 
}

function initConfig(){
	
	$.ajax({
		   type: "POST",
		   async: false,//同步发送请求数据
		   url: appPath+"/menu?method=getConfig",
		   dataType:"json",
		   beforeSend : function(){
//			   $.showProgress();
		   },
		   complete : function(){
//			   $.hideProgress();
		   },
		   timeout:120*1000,
	       success: function(data){
	    	   if(data){
	    		   bindFormData("config",data);
	    	   }
		   },
		   error:function(xhr,textStatus,errorThrown){
		   }
		}); 
}

</script>
  </body>
</html>